class_name DetectComponent
extends BaseComponent

var detector_dict:Dictionary = {}

func init_component(entity):
	super.init_component(entity)
	for detector in get_children():
		if detector is Detector:
			detector.init_detector(self)
			detector_dict[detector.detector_type] = detector
func get_detector(detector_type:GameEnum.DetectorType) -> Detector:
	if detector_dict.has(detector_type):
		return detector_dict[detector_type]
	return null
func detect():
	for detector in detector_dict.values():
		if detector.enable:
			detector.detect()
func control_detector_by_type(type:GameEnum.DetectorType,valid:bool):
	for detector in detector_dict.values().filter(func (d):return d.detector_type & type > 0):
		detector.enable = valid
func control_all_detector(valid:bool):
	for detector in detector_dict.values():
		detector.enable = valid

func _init() -> void:
	component_name = "DetectComponent"
	priority = 3 if priority == 0 else priority
func _physics_process(delta: float) -> void:
	detect()
